<template>
  <div id="bar_graph"></div>
</template>

<script>
import * as echarts from "echarts/core";
import { GridComponent } from "echarts/components";
import { BarChart } from "echarts/charts";
import { CanvasRenderer } from "echarts/renderers";

echarts.use([GridComponent, BarChart, CanvasRenderer]);

export default {
  name: "Bar",
  props: ["barData"],
  mounted() {
    var chartDom = document.getElementById("bar_graph");
    var myChart = echarts.init(chartDom);
    var option;

    option = {
      xAxis: {
        type: "value",
      },
      yAxis: {
        type: "category",
        inverse: true,
        data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
      },
      series: [
        {
          data: [120, 200, 150, 80, 70, 110, 130],
          type: "bar",
        },
      ],
    };

    if (this.barData) {
      option.series[0].data = this.barData.xAxis;
      option.yAxis.data = this.barData.yAxis;
    }
    option && myChart.setOption(option);
  },
};
</script>

<style scoped>
#bar_graph {
  width: 100%;
  height: 100%;
}
</style>